#coding=cp936
import os
import shutil
import win32api


def getFileVersion(file_name):
    info = win32api.GetFileVersionInfo(file_name, os.sep)
    ms = info['FileVersionMS']
    ls = info['FileVersionLS']
    version = '%d.%d.%d.%d' % (win32api.HIWORD(ms), win32api.LOWORD(ms), win32api.HIWORD(ls), win32api.LOWORD(ls))
    return version

if not os.path.exists('UpxApp'):
   os.makedirs('UpxApp')
shutil.copy('UniEntity.exe','UpxApp/UniEntity.exe')
os.system('upx -9 UpxApp/UniEntity.exe')
os.chdir('UpxApp')


#os.system('rar a -df UpxApp/SqlSrv/PRMS UpxApp/SqlSrv/PRMS.exe');
#os.system('rar a UpxApp/SqlSrv/PRMS UpxApp/SqlSrv/PRMS.exe');
rarcmd='rar a UniEntity_V%s.rar UniEntity.exe' % getFileVersion('UniEntity.exe')
os.system(rarcmd)
